package lime2;

import lights.interfaces.ITuple;
import sagroup.util.Generator;
import sagroup.util.Lights;

public class TupleGenerator implements Generator<ITuple> {
	public static ITuple[] toArray(int len) {
		TupleGenerator tg = new TupleGenerator();
		ITuple[] allTuples = new ITuple[len];
		for (int i = 0; i < len; i++) {
			allTuples[i] = (tg.next());
		}
		return allTuples;
	}

	@Override
	public ITuple next() {
		try {
			Generator[] gs = new Generator[] {
					RandomGenerator.Byte.class.newInstance(),
					RandomGenerator.Integer.class.newInstance(),
					RandomGenerator.String.class.newInstance(),
					RandomGenerator.Short.class.newInstance(),
					RandomGenerator.Long.class.newInstance() };
			Generator<Integer> bt;
			bt = RandomGenerator.Integer.class.newInstance();
			int len = (Math.abs(bt.next()) % 10) + LimeConstants.TAGS_NUMBER
					+ 1;
			Object[] fields = new Object[len];
			for (int i = 0; i < fields.length; i++) {
				int gsIndex = (Math.abs(bt.next()) % (gs.length));
				fields[i] = gs[gsIndex].next();
			}
			return Lights.creatTuple(fields);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// TODO Auto-generated method stub
		return null;
	}
}
